Attribute VB_Name = "ham"
'Public i As Integer
Public sonho As Double 'toan tu luu so nho
Public pheptoan As String ' cho biet phep toan nao duoc chon
Public th1 As Double 'luu toan hang thu nhat
Public th2 As Double  'luu toan hang thu hai
Public ketqua As Double 'luu ket qua
Public kt As Boolean 'kiem tra co phep toan nao duoc chon
'Public dodai As Integer
Public co As Boolean ' kiem tra text co gia tri hay chua
Public pi As Double
'"3.1415926535897932384626433832795"
Public heso As Integer


Public Sub chondec()
        main.bt0.Enabled = True
        main.bt1.Enabled = True
        main.bt2.Enabled = True
        main.bt3.Enabled = True
        main.bt4.Enabled = True
        main.bt5.Enabled = True
        main.bt6.Enabled = True
        main.bt7.Enabled = True
        main.bt8.Enabled = True
        main.bt9.Enabled = True
        main.btsin.Enabled = True
        main.btcos.Enabled = True
        main.bta.Enabled = False
        main.btb.Enabled = False
        main.btc2.Enabled = False
        main.btd.Enabled = False
        main.bte.Enabled = False
        main.btf.Enabled = False
        main.btcongtru.Enabled = True
 End Sub
Public Sub chonhex()
        main.bt0.Enabled = True
        main.bt1.Enabled = True
        main.bt2.Enabled = True
        main.bt3.Enabled = True
        main.bt4.Enabled = True
        main.bt5.Enabled = True
        main.bt6.Enabled = True
        main.bt7.Enabled = True
        main.bt8.Enabled = True
        main.bt9.Enabled = True
        main.bta.Enabled = True
        main.btb.Enabled = True
        main.btc2.Enabled = True
        main.btd.Enabled = True
        main.bte.Enabled = True
        main.btf.Enabled = True
        main.btsin.Enabled = False
        main.btcos.Enabled = False
        main.btcongtru.Enabled = False
 End Sub
Public Sub chonoct()
        main.bt0.Enabled = True
        main.bt1.Enabled = True
        main.bt2.Enabled = True
        main.bt3.Enabled = True
        main.bt4.Enabled = True
        main.bt5.Enabled = True
        main.bt6.Enabled = True
        main.bt7.Enabled = True
        main.bt8.Enabled = False
        main.bt9.Enabled = False
        main.bta.Enabled = False
        main.btb.Enabled = False
        main.btc2.Enabled = False
        main.btd.Enabled = False
        main.bte.Enabled = False
        main.btf.Enabled = False
        main.btsin.Enabled = False
        main.btcos.Enabled = False
        main.btcongtru.Enabled = False
End Sub
Public Sub chonbin()
        main.bt0.Enabled = True
        main.bt1.Enabled = True
        main.bt2.Enabled = False
        main.bt3.Enabled = False
        main.bt4.Enabled = False
        main.bt5.Enabled = False
        main.bt6.Enabled = False
        main.bt7.Enabled = False
        main.bt8.Enabled = False
        main.bt9.Enabled = False
        main.bta.Enabled = False
        main.btb.Enabled = False
        main.btc2.Enabled = False
        main.btd.Enabled = False
        main.bte.Enabled = False
        main.btf.Enabled = False
        main.btsin.Enabled = False
        main.btcos.Enabled = False
        main.btcongtru.Enabled = False
End Sub
Public Function giaithua(n As Integer) As Double
    Dim i As Integer, kq As Double ' i la bien chay, kq de luu ket qua
    'cho i chay tu 1 den n, moi lan lap se lay bien kq nhan voi i
    kq = 1
    For i = 1 To n
        kq = kq * i
    Next
    giaithua = kq
End Function

Public Function dectobin(n As Double) As String
    
    Dim i As String
    If n = 0 Then
    i = "0"
    ElseIf n = -1 Then
    i = -1
    Else
    i = ""
    Do Until n = 0
        i = CStr(n Mod 2 & i)
        n = Int(n / 2)
    Loop
    End If
    dectobin = i
    
End Function
Public Function bintodec(ByVal s As String) As Double
    If s = "0" Then
    bintodec = 0
    Else
     For i% = 1 To Len(s)
    bintodec = bintodec + Val(Mid(s, i, 1)) * 2 ^ (Len(s) - i)
    Next
    End If
End Function
Public Function octtodec(ByVal s As String) As Double
    For i% = 1 To Len(s)
    octtodec = octtodec + Val(Mid(s, i, 1)) * 8 ^ (Len(s) - i)
    Next
End Function
Public Function dectooct(n As Double) As String
    Dim i As String
    i = ""
    Do Until n = 0
        i = CStr(n Mod 8 & i)
        n = Int(n / 8)
    Loop
        dectooct = i
End Function
Public Function dectohex(so10 As Double) As String
    Dim T As String
    Do While (so10 <> 0)
        If (so10 Mod 16) > 9 Then
        Select Case (so10 Mod 16)
        Case 10
        m = "A"
        Case 11
        m = "B"
        Case 12
        m = "C"
        Case 13
        m = "D"
        Case 14
        m = "E"
        Case 15
        m = "F"
        End Select
        tam = tam & m
      so10 = (Val(so10) - (so10 Mod 16)) / 16
        Else
        tam = tam & so10 Mod 16
       so10 = (Val(so10) - (so10 Mod 16)) / 16
       End If
        Loop
        For i = Len(tam) To 1 Step -1
        T = T & Mid(tam, i, 1)
        Next
       dextohex = T
End Function
Public Function hextodec(so16)
    tong = 0
      For i = Len(so16) To 1 Step -1
      Select Case Mid(so16, i, 1)
      Case "A"
      tam = 10
      Case "B"
      tam = 11
      Case "C"
      tam = 12
      Case "D"
      tam = 13
      Case "E"
      tam = 14
      Case "F"
      tam = 15
      Case Else
      tam = Mid(so16, i, 1)
      End Select
     T = 1
     For j = 1 To Len(so16) - i
     T = 16 * T
     Next
      tong = tong + tam * T
     Next
     hextodec = tong
End Function


